<?php
declare(strict_types=1);
namespace App\Http\Controller;

use Swoft\Bean\Annotation\Mapping\Inject;
use Swoft\Http\Message\Request;
use Swoft\Http\Server\Annotation\Mapping\RequestMethod;
use Swoft\Http\Server\Annotation\Mapping\Controller;
use Swoft\Http\Server\Annotation\Mapping\RequestMapping;
use App\Model\Dao\Specific\IFriendServer;
use App\Model\Dao\Specific\IServerUser;
use Tool\AjaxReturn;
use Vadlidate\ValidateUserLogin;
use Validate\CheckParam;
use Swoft\Http\Server\Annotation\Mapping\Middleware;
use App\Http\Middleware\ValidateLoginMiddleware;

/**
 *
 * @Controller(prefix="/user")
 * @Middleware(ValidateLoginMiddleware::class)
 * @author Administrator
 *        
 */
class UserController
{
  
    /**
     * @Inject()
     * @var IServerUser
     */
    private IServerUser $server;
    
    
    /**
     * @RequestMapping(name="searchUser", method={RequestMethod::POST})
     * @param Request $request
     * @return array
     */
    public function searchUser(Request $request): array {
        
        $data = $request->post();
        
        vdump($data);
        
        $check = new CheckParam(ValidateUserLogin::getSearchRule(), $data);
        
        if (!$check->detectionParameters()) {
            return AjaxReturn::error($check->getErrorMessage());
        }
        
        return AjaxReturn::sendData($this->server->searchUserByUserName($data));
    }
}

